package Screens;


import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.io.IOException;
import java.util.ArrayList;

import main.Main;
import Volts.Monster;
import Volts.Player;

public class Screen extends Canvas{
	private static final long serialVersionUID = 1L;
	public String[][] battleGround = new String[Main.getWidth()/15 + 1][Main.getHeight()/16];	
	public ArrayList<Monster> monsters = new ArrayList<Monster>();
	
	public Screen(){
		this.setPreferredSize(Main.getSize());
		for(int i = 0; i < battleGround.length; i++){
			for(int j = 0; j < battleGround[0].length;j++){
				battleGround[i][j] = "0";
			}
		}
		try {
			init();
		} catch (IOException e) {}
	}
	
	LevelManager lm = new LevelManager();
	boolean went = false;
	boolean wont = false;
	private void init() throws IOException{
		for(int i = 0; i < battleGround.length; i++){
			for(int j = 0; j < battleGround[0].length;j++){
				battleGround[i][j] = lm.lines[j].words[i];
			}
		}
		/////////////
		
	}
	//43
	//30

	/*File myFile = new File("MyText.txt")
	BufferedReader reader = new BufferedReader(new FileReader(myFile));
	reader.readLine(); //you can combine this with a while loop (while line != null)
	reader.close();
	*/
	public void paintComponent(Graphics g){
		///*
		Graphics2D po = (Graphics2D)g;
		po.setColor(Color.white);
		po.fillRect(0, 0, Main.getWidth(), Main.getHeight());
		po.setColor(Color.black);
		for(int i = 0; i < battleGround.length; i++){
			for(int j = 0; j< battleGround[0].length; j++){
				po.drawRect(12 + i*14, 12 + j*14, 12, 12);
			}
		}
		
		//*/
		/////////////////////////////////////////////////
		for(int i = 0; i < battleGround.length; i++){
			for(int j = 0; j< battleGround[0].length; j++){
				if(battleGround[i][j].equals("*")){
				po.drawString("*", 16 + i*14, 24 + j*14);
				}else if(battleGround[i][j].equals("P")){
				po.drawString("P", 14 + i*14, 24 + j*14);
				//System.out.println(i + " " + j);
				if(went == false){
				//System.out.println("Draw P");
				Player.setPos(i,j);
				went = true;
				}
				
				}else if(battleGround[i][j].equals("M")){
					po.drawString("M", 14 + i*14, 24 + j*14);
					if(wont == false){
					monsters.add(new Monster(i,j));//setPos(i,j);
				}
				}else if(battleGround[i][j].equals("E")){
					po.drawString("E", 14 + i*14, 24 + j*14);
				}else{
					//g.drawString(j + "", 12 + i*14, 24 + j*14);
				}
			}
		}
			wont = true;
		
	}
}
